package cn.lingyangwl.agile.system;

import cn.lingyangwl.agile.model.module.auth.*;
import cn.lingyangwl.agile.model.module.config.*;
import cn.lingyangwl.agile.system.model.entity.*;
import cn.lingyangwl.agile.system.model.rqrs.accesskey.*;
import cn.lingyangwl.agile.system.model.rqrs.log.*;
import cn.lingyangwl.agile.system.model.rqrs.tenant.*;
import cn.lingyangwl.agile.system.model.rqrs.user.*;
import cn.lingyangwl.framework.core.response.*;
import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 *
 * @author shenguangyang
 */
@Slf4j
@Lazy
@Component
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class RemoteSystemFallbackFactory implements FallbackFactory<RemoteSystemService> {

    @Override
    public RemoteSystemService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemService(){
            @Override
            public Resp<Integer> deleteAccessLog(String endTime) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<AccessKeyResp> getAccessKeyBySecretId(String secretId) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<AccessKeyResp> getAccessKeyById(Long id) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<LoginUser> getLoginUser(LoginUserGetReq req) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<Long> saveUser(UserSaveReq req) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<?> removeUserById(Long userId) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<List<UserResp>> listUser(UserPageReq query) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<UserResp> getUserById(Long userId) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<?> deleteLoginUser(LoginUserDeleteReq req) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<List<UserResp>> listUserByIds(List<Long> userIds) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<SysUser> getUserByAccount(String account) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<String> saveTenant(TenantSaveReq req) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<?> deleteTenant(String tenantId) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<?> updateTenant(TenantUpdateReq req) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<?> initTenant() {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<String> getMgtSceneTenantId(String tenantId) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<ConfigInfo> getUseConfig(String configDefine) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<Map<String, List<String>>> listAssignRoleUrl(List<Long> roleIds) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<List<SysArea>> listAreaByNames(List<String> areaTypes, List<String> areaNames) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<List<TenantResp>> listTenantByIds(List<String> tenantIds) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<List<SysTenant>> pageTenant(Integer pageSize, Integer pageNum) {
                return Resp.fail("调用服务失败");
            }

            @Override
            public Resp<String> getMainTenantId(String tenantId) {
                return Resp.fail("调用服务失败");
            }
        };
    }
}
